<template>
    <div id="main">
        <div class="bar">
            <div class="left">
                代理商列表
            </div>
            <div class="right">
                <el-button type="success" size="mini"  @click="addMenu"> <i class="el-icon-plus"></i> 添加代理商</el-button>
            </div>
        </div>
        <div class="table">
            <el-table
                :data="tableData"
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                border
                default-expand-all
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column
                prop="userid"
                label="ID"
                align="center"
                sortable
               >
                </el-table-column>

                <el-table-column
                prop="nickname"
                align="center"
                label="昵称">
               </el-table-column>
               
                <el-table-column
                prop="username"
                align="center"
                label="账户">
                    
                </el-table-column>

                <!-- <el-table-column
                prop="password"
                align="center"
                label="密码">
                    
                </el-table-column> -->

                <el-table-column
                align="center"
                label="查看课程">
                    <template slot-scope="scope">
                        <el-button type="info" size="mini" @click="ShowClass(scope.row)" > 查看课程 </el-button>
                    </template>
                </el-table-column>




                <el-table-column
               
                align="center"
                label="状态">
                    <template slot-scope="scope">
                        <el-button :type="scope.row.status == 1 ? 'success':'danger' " size="mini" >
                            {{ scope.row.status == 1 ? "开启":"关闭"}}
                        </el-button>
                    </template>
                </el-table-column>

                <el-table-column
               
                align="center"
                label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="editMenu(scope.row)">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- dialog -->
        <dai-dialog :DialogData="DialogData" :FormData="FormData"  @update="getSchoolList"></dai-dialog>
        <dai-ke-dialog :classDia="classDia" :classData="classData" @update="getSchoolList"></dai-ke-dialog>

    </div>
</template>

<script>
    import DaiDialog from "@/components/dialog/DaiDialog"
    import DaiKeDialog from "@/components/dialog/DaiKeDialog"
    export default {
        data() {
            return {
                tableData: [],
                DialogData: {
                    title: "",
                    show: false,
                },
                FormData: {},
                classDia: {
                    show: false,
                    title: "查看课程",
                    userid: ""
                },
                classData: [],
            }
        },
        components: {
            DaiDialog,
            DaiKeDialog
        },
        computed: {
            token() {
                return localStorage.token; 
            }
        },
        mounted() {
            this.getSchoolList()
        },
        methods: {
            // 获取网站信息
            async getSchoolList() {
                let res = await this.$axios.post("/admin/user/agentshow", { token: this.token })
               // console.log(res);
                if(res.data.code == 200) {
                    this.tableData = res.data.data
                }
                
            },
            // 编辑菜单
            editMenu( user ) {
                this.DialogData = {
                    show: true,
                    title: "编辑代理商",
                    add: false,
                    edit: true
                }
                this.FormData = user
            },
            // 添加菜单
            addMenu() {
                this.DialogData = {
                    show: true,
                    title: "添加代理商",
                    add: true,
                    edit: false
                }
                this.FormData = {}
            },
            // 菜单状态改变
            async changeStatus( id ) {
                let res = await this.$axios.post("", {token: this.token, id })
              //  console.log(res);
                if(res.data.code == 204 || res.data.code == 202) {
                    this.$message.success("更新成功")
                    this.getSchoolList()
                } else {
                    this.$message.success("更新失败")
                    this.getSchoolList()
                }
                
            },
            // 查看课程
            async ShowClass( user ) {
               // console.log( user );
                let res = await this.$axios.post("/admin/user/agentclassshow", { userid: user.userid, token: this.token })
                // console.log(res);
                
                    this.classData = res.data.data
                    this.classDia = {
                        title: "查看课程",
                        show: true,
                        userid: user.userid
                    }
                
                console.log(this.classDia);
                
                
            },
        },
    }
</script>

<style lang="scss" scoped>
 #main {
     width: 100%;
     box-sizing: border-box;
     .bar {
         width: 100%;
         font-weight: bold;
         display: flex;
         justify-content: space-between;
         height: 40px;
         line-height: 40px;
         border-bottom: 1px solid #aaa;
     }
     .table {
         margin-top: 20px;
     }
     .pic {
         width: 40px;
         height: 40px;
         display: block;
     }
 }
</style>